package javaClassExercise.set;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * Created by lomo on 2017/3/14.
 */
public class HashMapTest {
    public static void main(String[] args) {

        int [] a = {2,3,2,2,1,4,2,2,2,7,9,6,2,2,3,1,0};

        Map<Integer, Integer> map = new HashMap<Integer,Integer>();
        //System.out.println(map.size());  // 0

        for(int i=0; i<a.length; i++){
            System.out.println(a.length); //17
            if(map.containsKey(a[i])){
                System.out.println("map集合里的Key恰好等于数组a的value的：" + map.get(i) + "||" + a[i]);
                int tmp = map.get(a[i]);
                tmp+=1;
                map.put(a[i], tmp);
            }else{
                map.put(a[i], 1);
            }
        }

        //keyset用来遍历Map
        Set<Integer> set = map.keySet();
        System.out.println("set size: " + set.size());  // 8
        for (Integer s : set) {
            if(map.get(s)>=a.length/2){
                System.out.println("get s ->" + map.get(s));  // get s ->8
                System.out.println(s);  // 2
            }
        }

        System.out.println(map.size()); //8
    }
}
